package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00102.SmileDay00102Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Adpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Bean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Contion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Model;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00103.TeenagerDay00103Presenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00103 extends BasterFragment implements TeenagerDay00103Contion.vier, OnRefreshLoadMoreListener {


    private RecyclerView TeenagerRecyclerView;
    public static SmartRefreshLayout TeenagerSmartRefreshLayout;
    public boolean isteenager = true;
    public int teebuju =0;
    public int teenum=20;
    public TeenagerDay00103Presenter presenter;
    public TeenagerDay00103Adpter adpter;




    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00103;
    }

    @Override
    public void initView() {
        TeenagerRecyclerView = (RecyclerView) findViewById(R.id.Teenager_RecyclerView);
        TeenagerSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Teenager_SmartRefreshLayout);
        TeenagerSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        TeenagerRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));


        presenter = new TeenagerDay00103Presenter(this, new TeenagerDay00103Model());
        presenter.teenager("/video/findVideos?currentPage="+teenum+"&pageSize=10");

    }

    @Override
    public void initDate() {

    }

    @Override
    public void getvier(List<TeenagerDay00103Bean.DataBean> dataBeans) {
        for (TeenagerDay00103Bean.DataBean dataBean : dataBeans) {
            dataBean.setTeenagertabyLayout(++teebuju);
            if (teebuju==4){
                teebuju=0;
            }
        }
        TeenagerSmartRefreshLayout.finishLoadMore();
        TeenagerSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new TeenagerDay00103Adpter(dataBeans);
            TeenagerRecyclerView.setAdapter(adpter);
        }else {
            if (isteenager){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        isteenager=false;
        teenum++;
        presenter.teenager("/video/findVideos?currentPage="+teenum+"&pageSize=10");
        Log.i("BlankFragmentDay001","---03加载:"+teenum);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (isteenager){
            teenum=20;
        }
        presenter.teenager("/video/findVideos?currentPage="+teenum+"&pageSize=10");
        Log.i("BlankFragmentDay001","---03刷新:"+teenum);

    }
}
